package com.changgou.user.controller;

import com.changgou.core.controller.AbstractCoreController;
import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.user.config.TokenDecode;
import com.changgou.user.pojo.Address;
import com.changgou.user.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author liyipeng
 * @date 2021-06-26 17:00
 */
@RestController
@RequestMapping("/address")
@CrossOrigin
public class AddressController extends AbstractCoreController<Address>{

    private AddressService  addressService;

    @Autowired
    private TokenDecode tokenDecode;


    @Autowired
    public AddressController(AddressService  addressService) {
        super(addressService, Address.class);
        this.addressService = addressService;
    }
    /****
     * 用户收件地址
     */
    @GetMapping(value = "/user/list")
    public Result<List<Address>> list(){
        //获取用户登录信息
        Map<String, String> userMap = tokenDecode.getUserInfo();
        String username = userMap.get("username");
        //查询用户收件地址
        List<Address> addressList = addressService.list(username);
        return new Result(true, StatusCode.OK,"查询成功！",addressList);
    }
}
